import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../views/Login.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Login',
    component: Login
  },
  {
    path: '/register',
    name: 'Register',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/Register')
  },
  {
    path: '/home',
    name: 'Home',
    component: () => import('../views/Home'),
    children:[
      {
        path: '/',
        name: 'GoodList',
        component: () => import('../views/Home/GoodList')
      },
      {
        path: '/goodList',
        name: 'GoodList',
        component: () => import('../views/Home/GoodList')
      },
      {
        path: '/goodAdd',
        name: 'GoodAdd',
        component: () => import('../views/Home/GoodAdd')
      },
      {
        path: '/goodReduce',
        name: 'GoodReduce',
        component: () => import('../views/Home/GoodReduce')
      },
      {
        path: '/orderList',
        name: 'OrderList',
        component: () => import('../views/Home/OrderList')
      },
      {
        path: '/orderDetail',
        name: 'OrderDetail',
        component: () => import('../views/Home/OrderDetail')
      },
      {
        path: '/service',
        name: 'Service',
        component: () => import('../views/Home/Service')
      },
      {
        path: '/storeDesign',
        name: 'StoreDesign',
        component: () => import('../views/Home/StoreDesign')
      },
      {
        path: '/modifyPwd',
        name: 'ModifyPwd',
        component: () => import('../views/Home/ModifyPwd')
      }
    ]
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

//解决router点击重复路径报错问题
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}

export default router
